package m.jclecai.com.adapter.holder;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.bean.reconmend.ReconmentContent;
import m.jclecai.com.data.Lecai_SDK;
import m.jclecai.com.fragment.RecommendFragment;
import m.jclecai.com.listener.Callback;
import m.jclecai.com.view.rounded.RoundedImageView;

/**
 * Created by ZD on 2017/7/19.
 */

public class RecomfamousHolder extends RecyclerView.ViewHolder {
    @BindView(R.id.iv_icon)
    RoundedImageView ivIcon;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.iv_type)
    ImageView ivType;
    @BindView(R.id.iv_position)
    ImageView ivPosition;
    @BindView(R.id.tv_position)
    TextView tvPosition;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_integral)
    TextView tvIntegral;
    @BindView(R.id.tv_desc)
    TextView tvDesc;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_start)
    TextView tvStart;
    @BindView(R.id.tv_time)
    TextView tvTime;
    private Callback mCallback;
    /**
     *   推荐解说
     */
    private ReconmentContent rc;

    Map<String,Integer> map = new HashMap<String,Integer>(){{
        put("彩票分析师",R.mipmap.famous_cpfxs);
        put("篮球名将",R.mipmap.famous_lqmj);
        put("篮球名人",R.mipmap.famous_lqmr);
        put("媒体名记",R.mipmap.famous_mtmj);
        put("社区名人",R.mipmap.famous_sqmr);
        put("TV大咖",R.mipmap.famous_tvdk);
        put("足球名将",R.mipmap.famous_zqmj);
        put("专业玩家",R.mipmap.famous_zywj);
    }};

    public RecomfamousHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
    }

    public void initData(Callback mCallback, ReconmentContent content) {
        this.mCallback = mCallback;
        this.rc = content;
        Glide.with(itemView.getContext()).
                load(content.getUser_face()).
                asBitmap().
                placeholder(R.drawable.my_head_de).
                into(ivIcon);
        tvName.setText(content.getUsername());
        tvDesc.setText(content.getTitle());
//        int jtype = obj.getIntValue("jtype");
        int jtype = 0;
        ivType.setImageResource(jtype == 0 ? R.mipmap.home_living_football : R.mipmap.home_living_basketball);
        ivPosition.setImageResource(map.get("社区名人"));
        tvPosition.setText(content.getTitle());
        tvType.setText(jtype == 0 ? "竞彩足球" : "竞彩篮球");
        tvTime.setText("开赛时间:"+content.getMatchtime());
        tvMoney.setText(content.getOne_money()+"元");
       /* tvPosition.setText(obj.getString("authdescription"));
        tvType.setText(jtype == 0 ? "竞彩足球" : "竞彩篮球");
        tvTime.setText("开赛时间:"+obj.getString("begintime"));
        tvMoney.setText(obj.getString("salepeice")+"元");*/
    }


    public void init(Callback mCallback, JSONObject obj) {
        this.mCallback = mCallback;
        Glide.with(itemView.getContext()).
                load(obj.getString("authheadImlUrl")).
                asBitmap().
                placeholder(R.drawable.my_head_de).
                into(ivIcon);
        tvName.setText(obj.getString("authName"));
        tvDesc.setText(obj.getString("title"));
        int jtype = obj.getIntValue("jtype");
        ivType.setImageResource(jtype == 0 ? R.mipmap.home_living_football : R.mipmap.home_living_basketball);
        ivPosition.setImageResource(map.get(obj.getString("authTag")));
        tvPosition.setText(obj.getString("authdescription"));
        tvType.setText(jtype == 0 ? "竞彩足球" : "竞彩篮球");
        tvTime.setText("开赛时间:"+obj.getString("begintime"));
        tvMoney.setText(obj.getString("salepeice")+"元");
    }


    @OnClick({R.id.ll_info, R.id.tv_desc, R.id.ll_money})
    void toRmDetail() {
        if (mCallback != null)
            Lecai_SDK.id = rc.getId();
            Lecai_SDK.persion_id = rc.getUser_id();
            Lecai_SDK.from = "recomment";
            mCallback.callback(RecommendFragment.JUMP.RmDetailActivity);
    }

    @OnClick(R.id.ll_user)
    void toRmFamous() {
        if (mCallback != null)
            Lecai_SDK.persion_id = rc.getUser_id();
            mCallback.callback(RecommendFragment.JUMP.RmFamousActivity);
    }
}
